<?php
class sample_detail1_model extends MY_Model {
	var $model = 'sample_detail1';
	
	function GetJSON($as_pk_master)
	{
		$ls_sql	= "	SELECT	* 
					FROM	sample_detail1 
					WHERE	pk_master = '".$as_pk_master."' 
					ORDER BY ".(post('sort')=='' ? 'index_no' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
	
	function GetDetailByID($as_pk_master)
	{
		$ls_sql	= "	SELECT	* 
					FROM	sample_detail1 
					WHERE	pk_master = '".$as_pk_master."' 
					ORDER BY index_no";
		
		$result	= $this->db->query($ls_sql);
		
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return NULL;
		}
	}
	
	function Add($arr_data){
		$this->db->insert('sample_detail1', $arr_data);
		
		/*$this->AuditTrail(	'sample_detail1',	// Table
							'Create',	// Action
							''			// Primary Key
							);*/
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('sample_detail1', $arr_data, $arr_rule);
		
		/*$this->AuditTrail(	'sample_detail1',		// Table
							'Update',				// Action
							json_encode($arr_rule)	// Primary Key
							);*/
	}
	
	function GetSingle($as_roleid){
		$result = $this->db->get_where('sample_detail1', array('ref_key' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_roleid)
	{
		$result = $this->db->get_where('sample_detail1', array('ref_key' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			$this->db->delete('sample_detail1', $arr_rule);
			
		/*	$this->AuditTrail(	'sample_detail1',		// Table
								'Delete',				// Action
								json_encode($arr_rule)	// Primary Key
								);*/
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>